package cn.walls1717.wallsmall.product.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

/**
 * Mybatis配置类
 *
 * @author walls1717
 * @since 2022/10/26 11:33
 **/
@Configuration
@EnableTransactionManagement
@MapperScan("cn.walls1717.wallsmall.product.dao")
public class MybatisConfig {

    /**
     * MybatisPlus分页插件
     * 
     * @return 拦截器
     */
    @Bean
    public MybatisPlusInterceptor interceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 请求的页面大于最大操作页，调回首页
        paginationInnerInterceptor.setOverflow(true);
        // 最大单页限制数量1000条
        paginationInnerInterceptor.setMaxLimit(1000L);
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }
}
